using System;
using System.Collections.Generic;
using iPhOwa.Exchange.ContentClasses;
using iPhOwa.Exchange.ContentClasses.Fields;
using iPhOwa.Exchange.WebDav.Methods;

namespace iPhOwa.Exchange.Managers
{
	/// <summary>
	/// Encapulates working with items.
	/// </summary>
	public static class ItemManager
	{
		/// <summary>
		/// Get a single message.
		/// </summary>
		public static Item Get(Uri path, OwaSession session)
		{
			var propFind = new PropFind(path, session, new string[0]);

			return propFind.Run();
		}

		/// <summary>
		/// Get's a list of message.
		/// </summary>
		/// <param name="path">The folder to get messages from.</param>
		/// <param name="startItem">The start index.</param>
		/// <param name="endItem">The end index.</param>
		/// <param name="session">The current session.</param>
		/// <returns>A collection of message items.</returns>
		public static ICollection<Item> GetList(Uri path, int startItem, int endItem, OwaSession session)
		{
			var properties = new[]
			                 	{
			                 			ItemFields.Read
			                 			, ItemFields.Href
			                 			, MessageFields.DateReceived
			                 			, MessageFields.FromName
			                 			, MessageFields.HasAttachment
			                 			, MessageFields.Priority
			                 			, MessageFields.Subject
			                 			, MessageFields.FlagCompleted
			                 			, MessageFields.MessageFlag
			                 			, MessageFields.DisplayTo
			                 			, ContactFields.FirstName
			                 			, ContactFields.LastName
			                 	};

			var search = new Search(path, session, properties) {Range = new Range(startItem, endItem)};

			return search.Run();
		}
	}
}